inconsistent behaviour of DXL script ?

Dear DXL experts!

I was writing the following scirpt to enable a multiple choice from a module directory list. Within my callback function I handle both cases "select" and "deselect" because my callback function will be called each time when I touch the directory list, regardless of the action (item highlighted or deselected) - so I have to take care about the actual selected (highlighted) directory list.

The problem is that the script or DXL itself sometimes (without any comprehensible reason) does not recognize correctly the taken action: at deselecting does not delete the item from my list, even the opposite happens, it will be added to the list. Very strange.
Can you see something? THX at all:
vasgyuszi
 

/* runLim = 0 means no restriction for total runtime,
 * i.e. no more timeouts will be reported.                                     */
pragma runLim, 0 
 
/*project to be displayed in list (with leading '/') */
string projectToView = "/M3AR"
 
/* first count all Folders in project */
Item    itm
Project prj = project projectToView
int     numberOfFolders = 0,
        numberOfModules = 0
 
/* walkthrough on all elements of the project and counting all folders and formal modules */
for itm in prj do {
    if (type(itm) == "Folder") {
        numberOfFolders++
    } else if (type(itm) == "Formal") {
                    numberOfModules++
            }
}
 
/* allocate double of needed space for security reason */
string sourceModuleName[numberOfModules*2]
 
/* read all folders to string array, for further use in list box */
string modules[numberOfFolders]
int i=0
for itm in prj do {
    if (type(itm) == "Folder") {
        modules[i]=fullName itm
        i++
    }
}
 
DB  moduleInputBox   = create    ("Choose module directory for modifying enum items", styleCentered)
DBE attributeColumn  = field     (moduleInputBox, "Name of Attribute Column:",   "RadioType",   20)
DBE oldEnumColumn    = field     (moduleInputBox, "Current name of enum item :", "All",         20)
DBE newEnumColumn    = field     (moduleInputBox, "New name of enum item:",      "M3AR Family", 20)
DBE sourceModuleList = multiList (moduleInputBox, "Choose module:",500, sizeof(modules), modules, sizeof(modules))
 
bool firstTime    = true,
     actionDel    = false
int  affectedItem = 0,
     currChoice   = 0,
     allChoice    = 0
 
    /* callback function for sourceModuleList -------------------------------- */
    void getSource(DBE sourceModuleList) {
 
        /*  i is the place of the selected item within the module list */
        int position = get sourceModuleList
        allChoice++
 
        if (firstTime){
            firstTime = false
            sourceModuleName[currChoice]=modules[position]
            currChoice++
            print "(FIRST) sourceModuleName:  " sourceModuleName[currChoice-1] "   currChoice = " currChoice "\n"
 
        } else{
            for (j=0; j<currChoice; j++){
                if (sourceModuleName[j]==modules[position]) {
                    print "(DEL-found)  sourceModuleName:  " sourceModuleName[j] "   position = " position "\n"
                    actionDel = true
                    affectedItem = j
                }
            }
    
            if (actionDel){
                if (currChoice<=1){
                    sourceModuleName[0] = ""
                } else {
                    for (j=0; j<currChoice-1; j++){
                        if (j >= affectedItem){
                            sourceModuleName[j] = sourceModuleName[j+1]
                        }
                    }
                }
                currChoice--
                actionDel = false
                print "(DEL-made)  currChoice = " currChoice "\n"
            } else{
                sourceModuleName[currChoice]=modules[position]
                currChoice++
                print "(INS)  sourceModuleName:  " sourceModuleName[currChoice-1] "   position = " position "\n"
            }
 
        }// else
 
        print "EVERY LOOP, currChoice = " currChoice "            allChoice = " allChoice "\n\n"
 
    } // getSource
 
 
set(sourceModuleList, getSource)
 
 
    /* ----------------------------------------------------------------------- */
    void getSourceInput(DB fieldBox) {
    
        string refAttribute = get attributeColumn
        string refOldEnum   = get oldEnumColumn
        string refNewEnum   = get newEnumColumn
 
        /* error handling if choice is empty */
        if (get sourceModuleList==null) {
            errorBox("Choose module directory!")
            return
        }
 
        /* link all modules in given folder */
        int step
        for (step=0; step<currChoice; step++){
            modifyAllFromModule(folder(sourceModuleName[step]), refAttribute, refOldEnum, refNewEnum)
        }
    }//getSourceInput
 
 
ok(moduleInputBox, getSourceInput)
show moduleInputBox

vasgyuszi - Mon Mar 15 10:35:16 EDT 2010

Re: inconsistent behaviour of DXL script ?
Mathias Mamsch - Mon Mar 15 18:32:23 EDT 2010

Hey vasgyuszi,

you code looks fine at the first glance. I think your problem is the multiList. You have to understand that there are two kinds of selections in the multiList. A "highlight" and a "selection". The "highlight"-items have a blue background while the selected item has a little dottet frame around it. Run your script, select one item and then use the "cursor up", "cursor down" keys. You will see the difference between hightlight and selection then. You callback will fire when the selection changes, which does not automatically mean that the hightlights change. This leads to inconsistencies between the highlighted items and your sourceModuleName array.

Anyway you are doing that all to complicated. If your goal is, to get the highlighted items of the listbox after the user presses ok, then you can do it simply like that

pragma runLim, 0 
  
string someArr[] = {"Mod1", "Mod2", "Mod3", "Mod4"}
 
DB  moduleInputBox   = create    ("Choose module directory for modifying enum items", styleCentered)
DBE sourceModuleList = multiList (moduleInputBox, "Choose module:",500, 6,someArr, 4)
 
// feel free to use show and a callback with button like you did
block moduleInputBox  
release moduleInputBox
hide moduleInputBox
 
int i 
 
// iterate over highlighted items ...
for i in sourceModuleList do {
    print "Doing it for module " someArr[i] "\n"
}

Re: inconsistent behaviour of DXL script ?
vasgyuszi - Mon Mar 15 21:03:42 EDT 2010

Mathias Mamsch - Mon Mar 15 18:32:23 EDT 2010

Hey vasgyuszi,

you code looks fine at the first glance. I think your problem is the multiList. You have to understand that there are two kinds of selections in the multiList. A "highlight" and a "selection". The "highlight"-items have a blue background while the selected item has a little dottet frame around it. Run your script, select one item and then use the "cursor up", "cursor down" keys. You will see the difference between hightlight and selection then. You callback will fire when the selection changes, which does not automatically mean that the hightlights change. This leads to inconsistencies between the highlighted items and your sourceModuleName array.

Anyway you are doing that all to complicated. If your goal is, to get the highlighted items of the listbox after the user presses ok, then you can do it simply like that

pragma runLim, 0 
  
string someArr[] = {"Mod1", "Mod2", "Mod3", "Mod4"}
 
DB  moduleInputBox   = create    ("Choose module directory for modifying enum items", styleCentered)
DBE sourceModuleList = multiList (moduleInputBox, "Choose module:",500, 6,someArr, 4)
 
// feel free to use show and a callback with button like you did
block moduleInputBox  
release moduleInputBox
hide moduleInputBox
 
int i 
 
// iterate over highlighted items ...
for i in sourceModuleList do {
    print "Doing it for module " someArr[i] "\n"
}

Thanks Mathias!

I thought at second look that my solution maybe unnecessary complicated ;)
My goal was to have a continuous list of directories after not specified number of mouse clicks.
It's allowed to the user to clicking any items any times and all that count is the currently highlighted items just before clicking on "OK" button. I needed that complicated list processing algorithm because without it my callback function will be called each time the user clicks on an item with the mouse. Regardless if the item will be deselected or selected, it will be added to my list of directories. It can be seen that is not the right way. So I have to distinguish between the two types of mouse-clicks (selecting/deselecting).
The algorithm itself seems now to be correct BUT sometimes (sporadic, not predictable) a delete action will be recognizes as an insert action and I don't know why.

I will take a look on your solution and refer on it.

Best regards,
vasgyuszi

Re: inconsistent behaviour of DXL script ?
Mathias Mamsch - Tue Mar 16 09:26:59 EDT 2010

vasgyuszi - Mon Mar 15 21:03:42 EDT 2010
Thanks Mathias!

I thought at second look that my solution maybe unnecessary complicated ;)
My goal was to have a continuous list of directories after not specified number of mouse clicks.
It's allowed to the user to clicking any items any times and all that count is the currently highlighted items just before clicking on "OK" button. I needed that complicated list processing algorithm because without it my callback function will be called each time the user clicks on an item with the mouse. Regardless if the item will be deselected or selected, it will be added to my list of directories. It can be seen that is not the right way. So I have to distinguish between the two types of mouse-clicks (selecting/deselecting).
The algorithm itself seems now to be correct BUT sometimes (sporadic, not predictable) a delete action will be recognizes as an insert action and I don't know why.

I will take a look on your solution and refer on it.

Best regards,
vasgyuszi

It is not random! I can tell you how you can reproduce the error.

Move your mouse over an item, press the left mouse button down (don't let it go yet) then move the mouse over another item and let go of the mouse button. It seems to happen randomly since it will happen every time, when you click on an items very fast and move your mouse in the short time while holding down the mousebutton to another item. Then highlight and selection will run out of sync.

Regards, Mathias

Re: inconsistent behaviour of DXL script ?
SystemAdmin - Tue Mar 16 11:58:52 EDT 2010

Just to be clear: Your script presents the user with a GUI. One element of the GUI is a multi-selectable list of modules. For every module selected, you want to run some function on that module? Is that correct?

Re: inconsistent behaviour of DXL script ?
vasgyuszi - Wed Mar 17 04:29:18 EDT 2010

vasgyuszi - Mon Mar 15 21:03:42 EDT 2010
Thanks Mathias!

I thought at second look that my solution maybe unnecessary complicated ;)
My goal was to have a continuous list of directories after not specified number of mouse clicks.
It's allowed to the user to clicking any items any times and all that count is the currently highlighted items just before clicking on "OK" button. I needed that complicated list processing algorithm because without it my callback function will be called each time the user clicks on an item with the mouse. Regardless if the item will be deselected or selected, it will be added to my list of directories. It can be seen that is not the right way. So I have to distinguish between the two types of mouse-clicks (selecting/deselecting).
The algorithm itself seems now to be correct BUT sometimes (sporadic, not predictable) a delete action will be recognizes as an insert action and I don't know why.

I will take a look on your solution and refer on it.

Best regards,
vasgyuszi

Thanks Mathias, I'm using now your much simple and errorfree working solution!

Best regards,
vasgyuszi

Re: inconsistent behaviour of DXL script ?
vasgyuszi - Wed Mar 17 04:31:42 EDT 2010

SystemAdmin - Tue Mar 16 11:58:52 EDT 2010
Just to be clear: Your script presents the user with a GUI. One element of the GUI is a multi-selectable list of modules. For every module selected, you want to run some function on that module? Is that correct?

@oaklodge:
Yes, your thoughts are right.

Re: inconsistent behaviour of DXL script ?
vasgyuszi - Wed Mar 17 04:33:13 EDT 2010

Mathias Mamsch - Tue Mar 16 09:26:59 EDT 2010
It is not random! I can tell you how you can reproduce the error.

Move your mouse over an item, press the left mouse button down (don't let it go yet) then move the mouse over another item and let go of the mouse button. It seems to happen randomly since it will happen every time, when you click on an items very fast and move your mouse in the short time while holding down the mousebutton to another item. Then highlight and selection will run out of sync.

Regards, Mathias

After a while of thinking I was going to something similar that the mouseclicks will be not properly recognized.

Now it works fine, THX!

vasgyuszi